//
//  GroupInfoActivityCell.m
//  SportSocial
//
//  Created by yull on 15/1/12.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "GroupInfoActivityCell.h"
#import "NSString+Size.h"

@implementation GroupInfoActivityCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WIDTH, 0, 0);
        
        CGRect rect = CGRectMake(10, 10, self.contentView.width - 20, self.contentView.height - 20);
        self.backView = [[UIView alloc] initWithFrame:rect];
        self.backView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [self.contentView addSubview:self.backView];
        
        rect = CGRectMake(5, 5, self.backView.width - 10, 15);
        self.statusLabel = [[UILabel alloc] initWithFrame:rect];
        self.statusLabel.backgroundColor = [UIColor clearColor];
        self.statusLabel.font = [UIFont systemFontOfSize:15.0f];
        self.statusLabel.textColor = [UIColor grayColor];
        [self.backView addSubview:self.statusLabel];
        
        rect = CGRectMake(5, self.statusLabel.bottom + 5, self.backView.width - 10, 0);
        self.activityDetailLabel = [[UILabel alloc] initWithFrame:rect];
        self.activityDetailLabel.backgroundColor = [UIColor clearColor];
        self.activityDetailLabel.font = [UIFont systemFontOfSize:14.0f];
        self.activityDetailLabel.textColor = self.statusLabel.textColor;
        self.activityDetailLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        self.activityDetailLabel.numberOfLines = 0;
        [self.backView addSubview:self.activityDetailLabel];
    }
    return self;
}

+ (CGFloat)calulateCellHeightWithText:(NSString *)text
{
    CGSize constrainedSize = CGSizeMake(SCREEN_WIDTH - 40, CGFLOAT_MAX);
    CGSize textSize = [text getSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedSize:constrainedSize];
    return textSize.height + 50;

}

- (void)drawCellWithActivity:(GroupActivity *)activity
{
//    self.backView.backgroundColor = [UIColor cyanColor];
    
    NSString *text = nil;
    if (activity.status == 0) {
        text = @"活动初始";
    }else if (activity.status == 1) {
        text = @"活动ing";
    }else {
        text = @"活动已结束";
    }
    
    self.statusLabel.text = text;
    
    self.activityDetailLabel.text = activity.content;
    
    CGSize constrainedSize = CGSizeMake(SCREEN_WIDTH - 40, CGFLOAT_MAX);
    CGSize textSize = [self.activityDetailLabel.text getSizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedSize:constrainedSize];
    self.activityDetailLabel.height = textSize.height;
}
@end
